Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

emphasize

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

emphasize

ANSI syntax highlighting for the terminal

  • 4.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
133K
increased by56.59%
Maintainers
1
Weekly downloads
 
Created
Source

emphasize

Build Coverage Downloads Size

ANSI syntax highlighting in for your terminal. Like highlight.js (through lowlight).

emphasize supports all 190 syntaxes of highlight.js.

Install

npm:

npm install emphasize

Use

Say example.css looks as follows:

@font-face {
  font-family: Alpha;
  src: url('Bravo.otf');
}

body, .charlie, #delta {
  color: #bada55;
  background-color: rgba(33, 33, 33, 0.33);
  font-family: "Alpha", sans-serif;
}

@import url(echo.css);

@media print {
  a[href^=http]::after {
    content: attr(href)
  }
}

And example.js contains the following:

var fs = require('fs')
var emphasize = require('emphasize')

var doc = fs.readFileSync('./example.css', 'utf8')

var output = emphasize.highlightAuto(doc).value

console.log(output)

Now, running node example yields:

@\u001b[32mfont-face\u001b[39m {
  \u001b[33mfont-family\u001b[39m: Alpha;
  \u001b[33msrc\u001b[39m: \u001b[31murl\u001b[39m(\u001b[36m'Bravo.otf'\u001b[39m);
}

\u001b[32mbody\u001b[39m, \u001b[34m.charlie\u001b[39m, \u001b[34m#delta\u001b[39m {
  \u001b[33mcolor\u001b[39m: \u001b[36m#bada55\u001b[39m;
  \u001b[33mbackground-color\u001b[39m: \u001b[31mrgba\u001b[39m(33, 33, 33, 0.33);
  \u001b[33mfont-family\u001b[39m: \u001b[36m\"Alpha\"\u001b[39m, sans-serif;
}

@\u001b[32mimport\u001b[39m url(echo.css);

@\u001b[32mmedia\u001b[39m print {
  \u001b[32ma\u001b[39m\u001b[35m[href^=http]\u001b[39m\u001b[35m::after\u001b[39m {
    \u001b[33mcontent\u001b[39m: \u001b[31mattr\u001b[39m(href)
  }
}

And looks as follows:

Screenshot showing the code in terminal

API

emphasize.registerLanguage(name, syntax)

Register a syntax. Like low.registerLanguage().

emphasize.highlight(language, value[, sheet])

Highlight value as a language grammar. Like low.highlight(), but the return object’s value property is a string instead of hast nodes.

You can pass in a sheet (Sheet?, optional) to configure the theme.

emphasize.highlightAuto(value[, sheet | options])

Highlight value by guessing its grammar. Like low.highlightAuto(), but the return object’s value property is a string instead of hast nodes.

You can pass in a sheet (Sheet?, optional) directly or as options.sheet to configure the theme.

Sheet

A sheet is an object mapping highlight.js classes to functions. The hljs- prefix must not be used in those classes. The “descendant selector” (a space) is supported.

Those functions receive a value (string), which they should wrap in ANSI sequences, and return. For convenience, chalk’s chaining of styles is suggested.

An abbreviated example is as follows:

{
  'comment': chalk.gray,
  'meta meta-string': chalk.cyan,
  'meta keyword': chalk.magenta,
  'emphasis': chalk.italic,
  'strong': chalk.bold,
  'formula': chalk.inverse
};

Emphasize in the browser

Do not require emphasize in the browser as that would include a very large file.

Instead, require emphasize/lib/core, and include only the used highlighters. For example:

var emphasize = require('emphasize/lib/core')
var js = require('highlight.js/lib/languages/javascript')

emphasize.registerLanguage('javascript', js)

emphasize.highlight('js', '"use strict";').value
// '\u001b[35m"use strict"\u001b[39m;'

License

MIT © Titus Wormer

Keywords

FAQs

Package last updated on 17 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc